package com.kaifamiao.month04.day27;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

public class Demo {

    public static void main(String[] args) {
        try {
            InputStream in = new FileInputStream("E:\\1101\\test\\test.txt");
            Charset cs = Charset.defaultCharset(); // 获取当前的默认编码格式
            byte[] bytes;
            switch (cs.toString()) {
                case "UTF-8"  ->  bytes= new byte[3];
                case "GBK" -> bytes = new byte[2];
                default -> bytes = new byte[4];
            }
            int a = in.read(bytes);
            System.out.println((char)a);
            System.out.println(in.available());
            bytes = in.readAllBytes();
            String str = new String(bytes);
            System.out.println(str);
            System.out.println(in.available());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
